# -*- coding: utf-8 -*-
"""
Created on Tue Feb 27 17:59:51 2024

@author: lishengpeng
"""

import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox

def open_file_dialog():
    # 选择文件窗口
    root = tk.Tk()  # 创建一个临时的Tk窗口，用于显示文件对话框
    root.withdraw()  # 隐藏主窗口，仅显示文件对话框

    # 打开文件对话框，设置默认行为为多选
    file_paths = filedialog.askopenfilenames(
        parent=root,
        title="选择文件",
        initialdir="/",  # 设置初始目录
        filetypes=(("All Files", "*.*"), ("Text Files", "*.txt"))  # 设置文件类型过滤器
    )

    path_list = []
    print("你选择了以下文件：")
    for path in file_paths:
        print(path)
        path_list.append(path)

    root.destroy()  # 关闭临时窗口
    return path_list
    
def pdf_transfer_word(path):
    import office
    export = path.split(':')[0]+":\\"
    print('导出路径为：'+export)
    office.pdf.pdf2docx(
        path,
        export
    )
    messagebox.showinfo(title='温馨提示', message='转换成功，存储地址为：'+export)


def pdf_to_word():
    # pdf转word入口方法
    file_paths = open_file_dialog()
    for path in file_paths:
        print('>>>>>>pdf--->word 选中文件，开始解析>>>>>>>>')
        pdf_transfer_word(path)
        
def smeil_click():
    messagebox.showinfo(title='温馨提示', message='欢迎提供您的意见到：2286384681@qq.com')
# 创建主窗口
tool = tk.Tk()
# 主窗口标题
tool.title("office文件转换")
tool.iconbitmap("favicon.ico")
# 主窗口大小
tool.geometry("700x300")
# 是否允许用户拉伸主窗口大小，默认为可更改，当设置为 resizable(0,0)或者resizable(False,False)时不可更改
# tool.resizable(0,0)
# 添加按钮
# tk.Button(tool,text='点击前往',bg='#7CCD7C',width=20,height=5,command=open_file_dialog).pack()
tk.Button(tool,text='pdf转Word',bg='#7CCD7C',width=20,height=5,command=pdf_to_word).grid(row=0,column=0,sticky="w",padx=10,pady=5)
tk.Button(tool,text='还要加点啥~',bg='#7CCD7C',width=20,height=5,command=smeil_click).grid(row=0,column=1,sticky="w",padx=10,pady=5)

tool.mainloop()
